package com.itheima.mapper;

import com.itheima.pojo.Member;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface ReportMapper {
    /**
     * 今日会员数
     * @param today
     * @return
     */
    @Select("select count(id) from t_member where regTime = #{today}")
     Integer findMemberCountByDate(String today) ;

    /**
     * 获取date前会员数
     * @param date
     * @return
     */
    @Select("select COUNT(*) from t_member where regTime<#{date} ")
    Integer getMembers(Date date);

    @Select("  select s.name,count(o.id) value\n" +
            "        from t_setmeal s,t_order o\n" +
            "        where s.id=o.setmeal_id\n" +
            "        group by s.name")
    List<Map<String, Object>> getSetMeal();

    /**
     * 会员总数
     * @return
     */
    @Select(" select count(id) from t_member")
    Integer findMemberTotalCount();

    /**
     * 本周新增会员数
     * @param firstDay4ThisWeek
     * @return
     */
    @Select("select count(id) from t_member where regTime = #{firstDay4ThisWeek}")
    Integer findMemberCount(String firstDay4ThisWeek);
//  今日预约数
@Select("select count(id) from t_order where orderDate=#{today}")
    Integer findOrderCountByDate(String today);
//今日导诊数
@Select("select count(id) from t_order where orderDate=#{today} and orderStatus='已到诊'")
    Integer findVisitCountByDate(String today);
//月预约数
@Select("select count(id) from t_order where orderDate =#{firstDay4ThisWeek}")
    Integer findOrderCount(String firstDay4ThisWeek);
//导诊数
@Select("select count(id) from t_order where orderDate = #{firstDay4ThisWeek} and orderStatus='已到诊'")
    Integer findVisitCount(String firstDay4ThisWeek);
//热门套餐
@Select("   select s.name,count(o.id) setmeal_count,\n" +
        "               count(o.id)/(select count(*) from t_order) proportion\n" +
        "        from t_order o,t_setmeal s\n" +
        "        where o.setmeal_id=s.id\n" +
        "        group by s.name\n" +
        "        order by setmeal_count desc\n" +
        "        limit 0,2")
    List<Map> findHotSetmeal();
}
